package org.surelink.radius.console;


import de.tototec.cmdoption.CmdOption;
import de.tototec.cmdoption.CmdlineParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.surelink.radius.console.message.Request;
import org.surelink.radius.console.message.RespBase;
import org.surelink.radius.console.message.Response;
import org.surelink.radius.server.AcctServer;
import org.surelink.radius.server.AuthServer;
import org.surelink.radius.server.ConsoleServer;

public class ShutdownProcess extends BaseProcess
{
//    @Autowired
//    private AuthServer authServer;
//
//    @Autowired
//    private AcctServer acctServer;


    class Config
    {
        @CmdOption(names = {"--help"}, description = "打印帮助", isHelp = true)
        private boolean help;

        @CmdOption(names = {"shutdown"}, hidden = true)
        private boolean shutdown;

    }


    public ShutdownProcess()
    {
        setOperate("shutdown");
    }

    @Override
    public Response process(Request req) throws Exception
    {
        Config config = new Config();
        CmdlineParser cp = new CmdlineParser(config);
        cp.setProgramName(getOperate());
        cp.parse(req.getCommand().split("\\s+"));

        if (config.help)
        {
            StringBuilder sb = new StringBuilder();
            cp.usage(sb);
            return new Response(RespBase.SUCCESS.getCode(), sb.toString());
        }

        if(config.shutdown)
        {
//            authServer.stop();
//            acctServer.stop();
            System.exit(0);

        }

        return RespBase.MSG_FORMAT_ERR;
    }
}
